package com.dtsz.m2.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.android.volley.Request;
import com.dtsz.m2.R;
import com.dtsz.m2.config.UrlConfig;
import com.dtsz.m2.ui.base.BaseActivity;
import com.dtsz.m2.ui.model.PayOrderVo;
import com.dtsz.m2.utils.PackageUtils;
import com.dtsz.m2.utils.StringUtils;
import com.dtsz.m2.volley.state.HUCState;

public class Pay1Activity extends BaseActivity {
    private EditText edAddress;

    private PayOrderVo payOrderVo = new PayOrderVo();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_pay1);
        super.onCreate(savedInstanceState);
        tvActionbarTitle.setText("转出地址");
    }

    @Override
    public void initView() {
        super.initView();
        edAddress = findViewById(R.id.et_address);
    }

    @Override
    public void initClick() {
        super.initClick();
        findViewById(R.id.bt_pwd).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.bt_pwd:
                loading();
                String address = edAddress.getText().toString();
                if (StringUtils.isEmpty(address)) {
                    showToast("请填写地址");
                    return;
                }
                String usersionC = PackageUtils.getAppVersionName(this);
                payOrderVo.setRemake(usersionC);
                payOrderVo.setAddress(address);
                hucRequestInterfase.executeStr(this, String.class,
                        HUCState.HUC_REQEUST_CODE_1, Request.Method.POST, UrlConfig.GETUSERS_URL,
                        hucParameInterfase.getRequestParameter(payOrderVo), true);
                break;
        }
    }

    @Override
    public void onSuccessfulStrType(int inputType, Object response) {
        super.onSuccessfulStrType(inputType, response);
        switch (inputType) {
            case HUCState.HUC_REQEUST_CODE_1:
                String str = (String) response;
                if ("地址不存在".equals(str)) {
                    showToast(str);
                } else if ("暂时关闭".equals(str)) {
                    showToast(str);
                } else {
                    Intent intent = new Intent();
                    intent.setClass(this, Pay2Activity.class);
                    intent.putExtra("name", str);
                    intent.putExtra("address", payOrderVo.getAddress());
                    startActivity(intent);
                    finish();
                }
                break;
        }
        loadDismiss();
    }
}
